#!/bin/sh
#VER="$(git rev-list HEAD --first-parent --count)"

VER="$(cut -c 7,8,9,10,11 release/LastVersion.txt)"
#检查是否版本号是一个数字
isNum=1; 
expr $VER + 0 &>/dev/null
[ $? -ne 0 ] && { isNum=0;} 
if [ "$isNum" -ne "1" ] ; then
	VER=10000;
else
	VER=$((10#${VER}+1))
fi

HASH="$(git log --pretty=format:%h -1)"
v="$1";
sv="$2";

if [ -z "$1" ]; then
  v="6.0.0"
fi

if [ -z "$sv" ]; then
  sv="nightly"
fi

version=$v"."$VER"."$HASH"."$sv
npm install
webpack --progress --profile --colors --display-modules --config webpack.pro.config.js

if [ $sv = "beta" ]; then
	sed -i "" '/\/mapp\//s/\/mapp\//\/mapp-prd\//g' build/package/app.js
fi
java -jar public.jar $version

echo $version >"release/LastVersion.txt"